﻿using ConfigMgmtEx;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ConfigMgmtExTest
{
    
    
    /// <summary>
    ///This is a test class for ConfManagerTest and is intended
    ///to contain all ConfManagerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ConfManagerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for GetConfigEntry
        ///</summary>
        [TestMethod()]
        public void GetConfigEntryTest()
        {
            ConfManager cm = new ConfManager();
            cm.DefaultCfg.Add("Setting 1", "Default Value 1");
            cm.DefaultCfg.Add("Setting 2", "Default Value 2");
            cm.DefaultCfg.Add("Setting 3", "Default Value 3");
            Assert.AreEqual(cm.GetConfigEntry("Setting 1").ConfigValue, "Default Value 1");
            Assert.AreEqual(cm.GetConfigEntry("Setting 2").ConfigValue, "Default Value 2");
            Assert.AreEqual(cm.GetConfigEntry("Setting 3").ConfigValue, "Default Value 3");

            cm.AppCfg.Add("Setting 1", "Is now AppSetting 1");
            Assert.AreEqual(cm.GetConfigEntry("Setting 1").ConfigValue, "Is now AppSetting 1");
            Assert.AreEqual(cm.GetConfigEntry("Setting 2").ConfigValue, "Default Value 2");
            Assert.AreEqual(cm.GetConfigEntry("Setting 3").ConfigValue, "Default Value 3");

            cm.UserCfg.Add("Setting 2", "And now Setting 2 is a user setting");
            Assert.AreEqual(cm.GetConfigEntry("Setting 1").ConfigValue, "Is now AppSetting 1");
            Assert.AreEqual(cm.GetConfigEntry("Setting 2").ConfigValue, "And now Setting 2 is a user setting");
            Assert.AreEqual(cm.GetConfigEntry("Setting 3").ConfigValue, "Default Value 3");

            cm.SaveAsXml("MyConfigTestData.xml");
            cm = null;
            cm = ConfManager.CreateFromXml("MyConfigTestData.xml");

            Assert.AreEqual(cm.GetConfigEntry("Setting 1").ConfigValue, "Is now AppSetting 1");
            Assert.AreEqual(cm.GetConfigEntry("Setting 2").ConfigValue, "And now Setting 2 is a user setting");
            Assert.AreEqual(cm.GetConfigEntry("Setting 3").ConfigValue, "Default Value 3");
        }

    }
}
